package com.hexgon.plugins.rabbitmq;

import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * MultiRabbitBootstrapConfiguration
 * @author: XuZhibin
 * @date: 2023/11/12 12:27
 * @version: v1.0
 * @attention: 支持 MultiRabbitListenerAnnotationBeanPostProcessor 替换原来的 RabbitListenerAnnotationBeanPostProcessor
 */
public class MultiRabbitBootstrapConfiguration implements ImportBeanDefinitionRegistrar {

    public MultiRabbitBootstrapConfiguration() {
    }

    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        if (!registry.containsBeanDefinition("org.springframework.amqp.rabbit.config.internalRabbitListenerAnnotationProcessor")) {
            registry.registerBeanDefinition("org.springframework.amqp.rabbit.config.internalRabbitListenerAnnotationProcessor", new RootBeanDefinition(MultiRabbitListenerAnnotationBeanPostProcessor.class));
        }

        if (!registry.containsBeanDefinition("org.springframework.amqp.rabbit.config.internalRabbitListenerEndpointRegistry")) {
            registry.registerBeanDefinition("org.springframework.amqp.rabbit.config.internalRabbitListenerEndpointRegistry", new RootBeanDefinition(RabbitListenerEndpointRegistry.class));
        }

    }
}
